import 'package:freezed_annotation/freezed_annotation.dart';

part 'application_bean.freezed.dart';
part 'application_bean.g.dart';

@freezed
class ApplicationBean with _$ApplicationBean {
  factory ApplicationBean({
    required Feed? feed,
  }) = _ApplicationBean;

  factory ApplicationBean.fromJson(Map<String, Object?> json) =>
      _$ApplicationBeanFromJson(json);
}

@freezed
class Feed with _$Feed {
  factory Feed({
    Author? author,
    List<Entry>? entry,
    EntryAttributes? updated,
    EntryAttributes? rights,
    EntryAttributes? title,
    EntryAttributes? icon,
    List<Link>? link,
    EntryAttributes? id,
  }) = _Feed;

  factory Feed.fromJson(Map<String, Object?> json) => _$FeedFromJson(json);
}

@freezed
class Author with _$Author {
  factory Author({EntryAttributes? name, EntryAttributes? uri}) = _Author;

  factory Author.fromJson(Map<String, Object?> json) => _$AuthorFromJson(json);
}

@freezed
class Entry with _$Entry {
  factory Entry({
    @JsonKey(name: 'im:name') required EntryAttributes? imName,
    @JsonKey(name: 'im:image') required List<EntryAttributes>? imImage,
    EntryAttributes? summary,
    @JsonKey(name: 'im:price') required EntryAttributes? imPrice,
    @JsonKey(name: 'im:contentType') required ImContentType? imContentType,
    required EntryAttributes? rights,
    required EntryAttributes? title,
    required List<Link>? link,
    required EntryAttributes? id,
    @JsonKey(name: 'im:artist') required EntryAttributes? imArtist,
    ImContentType? category,
    @JsonKey(name: 'im:releaseDate') required EntryAttributes? imReleaseDate,
  }) = _Entry;
  factory Entry.fromJson(Map<String, Object?> json) => _$EntryFromJson(json);
}

@freezed
class EntryAttributes with _$EntryAttributes {
  factory EntryAttributes({
    String? label,
    Attributes? attributes,
  }) = _EntryAttributes;

  factory EntryAttributes.fromJson(Map<String, Object?> json) =>
      _$EntryAttributesFromJson(json);
}

@freezed
class Attributes with _$Attributes {
  factory Attributes({
    @JsonKey(name: 'im:id') required String? imId,
    @JsonKey(name: 'im:bundleId') required String? imBundleId,
    required String? href,
    required String? term,
    required String? scheme,
    required String? label,
    required String? rel,
    required String? type,
    required String? amount,
    required String? currency,
    required String? title,
    @JsonKey(name: 'im:assetType') required String? imAssetType,
    required String? height,
  }) = _Attributes;

  factory Attributes.fromJson(Map<String, Object?> json) =>
      _$AttributesFromJson(json);
}

@freezed
class ImContentType with _$ImContentType {
  factory ImContentType({
    required EntryAttributes? attributes,
  }) = _ImContentType;

  factory ImContentType.fromJson(Map<String, Object?> json) =>
      _$ImContentTypeFromJson(json);
}

@freezed
class Link with _$Link {
  factory Link({
    required EntryAttributes? attributes,
    @JsonKey(name: 'im:duration') required EntryAttributes? imDuration,
  }) = _Link;

  factory Link.fromJson(Map<String, Object?> json) => _$LinkFromJson(json);
}

@freezed
class DetailInfoResp with _$DetailInfoResp {
  factory DetailInfoResp({
    required int resultCount,
    required List<DetailInfo> results,
  }) = _DetailInfoResp;

  factory DetailInfoResp.fromJson(Map<String, Object?> json) =>
      _$DetailInfoRespFromJson(json);
}

@freezed
class DetailInfo with _$DetailInfo {
  factory DetailInfo({
    required double averageUserRatingForCurrentVersion,
    required int userRatingCountForCurrentVersion,
    required int trackId,
  }) = _DetailInfo;

  factory DetailInfo.fromJson(Map<String, Object?> json) =>
      _$DetailInfoFromJson(json);
}
